<?php $gridId=uniqid(); ?>
//每页显示记录数
var mypagedata=[
				['10','10'],
				 ['15','15'],
				 ['20','20'],
				 ['40','40'],
				 ['200','200']
				 ];	
var page_size_store=new Ext.data.SimpleStore({
									   fields:[
											   {name:'id'},
											   {name:'name'},
									   		  ]
									   });
page_size_store.loadData(mypagedata);
var pagesize_combo=new Ext.form.ComboBox({
										 store:page_size_store,
										 width:50,										
										 emptyText:'10',
										 mode:'local',
										 triggerAction:'all',
										 valueField:'name',
										 displayField:'id'
										 });
pagesize_combo.on('select',function(e){										
										var pagesize=parseInt(e.getValue());
										pagBar.pageSize=pagesize;
										ds.load({params:{start:0,limit:pagesize}});
										});	

//定义分页条栏				 
var pagBar=new Ext.PagingToolbar({
										pageSize:20,
										store:ds,
										displayInfo:true,
										displayMsg:'第{0}到{1}条记录 共{2}条记录',
										emptyMsg:'没有数据记录',
										//plugins: filters,
										items:['-','每页显示',pagesize_combo,'条记录','-']
									 });
//定义容器
var grid=new Ext.grid.EditorGridPanel({
									id:'grid_'+ExtId,
									renderTo:'grid_<?=$gridId?>',
									store:ds,
									cm:cm,									
									height:500,
									minHeight:300,
									autoWidht:true,								
									loadMask:{msg:'加载服务端数据中',store:ds},	
									autoScroll:true,
									stripeRows:true,									
        							animCollapse: false,
									monitorWindowResize: true,	
									title:gridTitle,
									clicksToEdit:true,                                    
									sm:new Ext.grid.CheckboxSelectionModel({singleSelect:false}),
									tbar:tb,
									bbar:pagBar,
                                    stateful:true,  
									stateId:'link_'+module,
                                    trackMouseOver:true,
                                    viewConfig:{
                                  		emptyText:'<center><font style="font-weight:bold;font-size:16px">没有数据记录</font></center>',
           								forceFit:true
                                    	}
									});
                                    
                                    
//显示数据
ds.load({params:{start:0,limit:20}});

grid.render();

grid.on("afteredit",afterEdit,grid);

function afterEdit(e){
	Ext.getCmp('menu_save'+ExtId).setDisabled(false);	
}

function menuDel(){												
												var selectRows=grid.getSelectionModel().getSelections();												
												if(selectRows.length==0){
													Ext.MessageBox.alert('提示','请选择一条数据');
													}
												else{		
													var message="";
													for(var i=0;i<selectRows.length;i++){
														if(i!=0){
															message+=",";
															}
														message+=selectRows[i].get(dataId);
														}
													Ext.Ajax.request({
																	 url:menuDelUrl,
																	 params:{id:message},																																		 																	success:function(response,option){
																var temp=Ext.util.JSON.decode(response.responseText);																
																ds.load({params:{start:0,limit:30}});
																grid.render();
																		 },
																	failure:function(response,option){
																		var temp=Ext.util.JSON.decode(response.responseText);
																		Ext.MessageBox.alert('waring',temp.msg);
																		}
																	 });
													}
												}

function menuSave(){
	afterEditSave();
	Ext.getCmp("menu_save"+ExtId).setDisabled(true);
}

function afterEditSave(){
	var　modified　=　ds.modified;
	var json=[];
	Ext.each(modified,function(field){
						json.push(field.data);
						});
	if(json.length>0){
		Ext.Ajax.request({
						 url		: menuEditUrl,
						 params		: {data:Ext.util.JSON.encode(json)},
						 method		: 'POST',
						 success	: function(response){
							 	Ext.Msg.alert('信息','数据更新成功',function(){																	
										Ext.getCmp('content').getActiveTab().getUpdater().refresh();																
								});
							 }
						 });
		}
	else{
		Ext.Msg.alert("信息","没有修改任何信息");
		}
	//alert(e.field);
	//alert(e.record.get('role'));
}
 
});
</script>
<body style="width:98%;height:100%">
<div id='grid_<?=$gridId?>'></div>
</body>
</html>

